﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCPnuts.ISkyDiskFileSystem.Interfaces;
using CCPnuts.ISkyDiskFileSystem.Exceptions;
using System.Collections;
using CCPnuts.Pack;

namespace CCPnuts.ISkyDiskFileSystem
{
    public class SkyElementCollection : PackerBase, IEnumerable<SkyElement>
    {
        #region Packed Target

        internal SkyElementCollection(IPacked target) : base(target) { }

        internal new I_SkyElementCollection Packed { get { return (I_SkyElementCollection)base.Packed; } }

        #endregion

        #region Proxy Members

        #region Essential Methods

        /// <summary>
        /// check if the collection contains the item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        bool Contains(SkyElement item)
        {
            return Packed.Contains((I_SkyElement)Util.NNTar(item));
        }

        /// <summary>
        /// Gets the count of items
        /// </summary>
        public int Count { get { return Packed.Count; } }

        #endregion

        #region IEnumerable<SkyElement> Members

        public IEnumerator<SkyElement> GetEnumerator()
        {
            var enu = Packed.GetEnumerator();
            if (enu == null)
            {
                throw new ImplementError("The GetEnumerator method of SkyElementCollection can not return a null.");
            }
            return new EnumeratorPacker<SkyElement, I_SkyElement>(enu);
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return (IEnumerator)GetEnumerator();
        }

        #endregion

        #endregion
    }

    public static partial class PackedInfos
    {
        public static PackedInfo SkyElementCollection { get { return new PackedInfo(p => new SkyElementCollection(p)); } }
    }
}
